package  com.makinolo.rlvforge.tacx.utils
{
import flash.utils.ByteArray;
	
public class StringUtils
{
	public static function replicate(charcode:int, stringLength:int):String
	{
		var ret:String = "";
		for (var i:int=0; i<stringLength; i++)
			ret += String.fromCharCode(charcode);
		  
		return ret;
	}

	/**
	 * Fills the String with the specified char until reaching len 
	 * @param str
	 * @param c
	 * @return
	 */
	public static function stuff(str:String, c:int, len:int):String
	{
		var ret:String = "";
		if (str.length > len)
			ret = str.substring(0,len);
		else
			ret = str + replicate(c, len-str.length);
		return ret;
	}
	
	public static function StringToTacxBytes(str:String):ByteArray
	{
		var ret:ByteArray = new ByteArray();
		for (var i:int=0; i<str.length; i++)
		{
			ret.writeByte(str.charCodeAt(i));
			ret.writeByte(0);
		}
		ret.writeByte(0);
		ret.writeByte(0);
		return ret;
	}
}

}